var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
const cookieSession = require("cookie-session");
//这种可以解决所有的跨域问题
// const cors = require("cors");

// var indexRouter = require("./routes/index");
// var usersRouter = require("./routes/users");
var apiRouter = require("./routes/api");

var app = express();

// app.use(cors());
app.use(
  cookieSession({
    name: "token",
    keys: ["abc"]
  })
);
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

// app.use("/", indexRouter);
// app.use("/users", usersRouter);
app.use("/api", apiRouter);

module.exports = app;
